#include <iostream>
#include <functional>

using std::cout;
using std::endl;
using std::bind;

void func(int x1, int x2, int x3, const int &x4, int x5)
{
    cout << "x1 = " << x1 << endl
         << "x2 = " << x2 << endl
         << "x3 = " << x3 << endl
         << "x4 = " << x4 << endl
         << "x5 = " << x5 << endl;
}

void test()
{
    int number = 100;
    using namespace std::placeholders;
    //占位符
    //占位符整体代表的是函数的形参
    //占位符中的数字代表是实参
    //bind函数在传参的时候，默认采用的是值传递
    //std::cref = const reference是引用的包装器
    //std::ref = reference是引用的包装器
    auto f = bind(&func, 10, _4, _3, std::cref(number), number);
    number = 300;
    f(1, 2, 3, 11, 33, 55, 66);//多余的参数直接丢掉
    /* f(1, 2, 3, 11);//多余的参数直接丢掉 */

    /* bind(&func,_1, _1, _1, _1, _2); */
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

